<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新建合同</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/css/public.css"  media="all">
	<link rel="stylesheet" href="__PUBLIC__/kindeditor/themes/default/default.css" />
		<script charset="utf-8" src="__PUBLIC__/kindeditor/kindeditor-min.js"></script>
		<script charset="utf-8" src="__PUBLIC__/kindeditor/lang/zh_CN.js"></script>
		<!--
		这里不需要引入jquery
		注意：textarea的name必须和js里面的K.create('textarea[name="content"]',这个相等
		-->
		<script src="__PUBLIC__/kindeditor/jquery.js"></script>
		<script>
			var editor2;
			KindEditor.ready(function(K) {
				editor2 = K.create('textarea[name="content"]', {
					allowFileManager : true,
					afterBlur:function() {
						this.sync();
					}
				});
				
				var editor = K.editor({
					allowFileManager : true
				});
				$(".upload_img").each(function(k,v){ //循环上传按钮、
					$(v).click(function(){ //每个上传按钮的点击事件
						editor.loadPlugin('image', function() {
							editor.plugin.imageDialog({
								imageUrl:$(v).prev().val(),
								clickFn : function(url, title, width, height, border, align) {
									$(v).prev().val(url); //为他之前的input赋值
									$(v).prev().prev().attr("src",url); //为他之前的之前的img赋值
									editor.hideDialog();
								}
							});
						});
					});
				})
			});
		</script>
</head>
<body>
<div class="layui-conter">
    <div class="layui-col-md12">
        <div class="navigation">
            <span>行政></span><span>合同管理></span><span>新建合同</span>
        </div>
        <div class="white-conter selsectSet">
            <div class="title-blue"><b>新建合同</b></div>
            <div style="margin-top: 20px">
                <form class="layui-form" action="{:U('Contract/newContract')}" method="post" onsubmit="return check_form();">
                    <input type="hidden" name="id" value="{$contract_data.id}">
					<div class="layui-col-md6">
                        <div class="layui-col-md10">
                            <div class="form-item">
                                <div class="label-div">
                                    <label class="form-label"><b>合同名称</b></label>
                                </div>
                                <div class="input-block">
                                    <input type="text" value="{$contract_data.contractname}" name="contractName" autocomplete="off" placeholder="请输入..." class="layui-input">
                                </div>
                            </div>
                            <div class="form-item">
                                <div class="label-div">
                                    <label class="form-label"><b>合同编号</b></label>
                                </div>
                                <div class="input-block">
                                    <input type="text" name="contractId" value="{$contract_data.contractid}" autocomplete="off" placeholder="请输入..." class="layui-input">
                                </div>
                            </div>
                            <div class="form-item">
                                <div class="label-div">
                                    <label class="form-label"><b>签订日期</b></label>
                                </div>
                                <div class="input-block">
                                    <input type="text" name="contractStart" value="{$contract_data.contractstart}" id="signDate" lay-verify="date" placeholder="请选择"  class="layui-input">
                                </div>
                            </div>
                            <div class="form-item" >
                                <div class="label-div">
                                    <label class="form-label"><b>结束日期</b></label>
                                </div>
                                <div class="input-block">
                                    <input type="text" name="contractEnd" value="{$contract_data.contractend}" id="endDate" lay-verify="date" placeholder="请选择"  class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item" style="margin-bottom: 25px;">
                            	<div class="label-div">
                            		<label class="form-label"><b>选择报名学员</b></label>
                            	</div>
                            	<div class="layui-input-inline">
                            		<select name="student" lay-verify="required" lay-filter="student">
                            				<option value="">请选择</option>
                            				<foreach name="student_data" item="s">
                            					<option value="{$s.id}" <if condition="$s['id'] eq $contract_data['student']"> selected </if>>{$s.name}</option>
                            				</foreach>
                            		</select>
                            	</div>
                            </div>
							<div class="photo">
                                <p>上传合同</p>
                                <div>
									<img src="{$contract_data.contract_img}" style="background: #dce6f0;min-width: 100%;">
									<input value="{$contract_data.contract_img}" type="hidden" name="contract_img" /> 
									<input type="button" class="upload_img" value="选择图片" style="line-height: 48px;width: 100%;text-align: center;display: block; background: #666;color: #fff;opacity:0.4;bottom: 0;"/>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6" style="float: left;">
                        <div class="layui-col-md10" id="student_show">
                            <div class="form-item">
                                <div class="label-div">
                                    <label class="form-label"><b>联系人</b></label>
                                </div>
                                <div class="input-block">
                                    <input type="text" value="{$contract_data.contractlinkman}" name="contractLinkman" autocomplete="off" placeholder="请输入..." class="layui-input">
                                </div>
                            </div>
                            <div class="form-item">
                                <div class="label-div">
                                    <label class="form-label"><b>联系电话</b></label>
                                </div>
                                <div class="input-block">
                                    <input type="text" value="{$contract_data.contractphone}" name="contractPhone" autocomplete="off" placeholder="请输入十一位数手机号码..." class="layui-input">
                                </div>
                            </div>
							<div class="form-item">
								<div class="label-div">
									<label class="form-label"><b>业务员</b></label>
								</div>
								<div class="input-block">
									<input type="hidden" name="salesman" value="{$contract_data.salesman}"><p>{$contract_data.xs_name}</p>
								</div>
							</div>
							<div class="form-item">
								<div class="label-div">
									<label class="form-label"><b>报名课程</b></label>
								</div>
								<div class="input-block">
									<p>{$contract_data.curriculum_name}</p><br/><p>{$contract_data.discount_name}</p>
								</div>
							</div>
							<div class="form-item">
								<div class="label-div">
									<label class="form-label"><b>合同费用</b></label>
								</div>
								<div class="input-block">
									<input type="hidden" value="{$contract_data.contractcost}" name="contractCost" autocomplete="off" class="layui-input">{$contract_data.contractcost}
								</div>
							</div>
                            <div class="form-item">
                                <div class="label-div">
                                    <label class="form-label"><b>重要条款</b></label>
                                </div>
                                <div class="input-block input-block">
                                        <textarea name="terms" placeholder="请输入内容" class="layui-textarea" style="height: 120px;">{$contract_data.terms}</textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md12">
                        <div class="button-block">
                            <button class="layui-btn layui-btn-xs layui-btn-normal" lay-submit="" style="height: 30px;width: 60px;">提交</button>
                            <a href="{:U('Contract/index')}" class="layui-btn layui-btn-xs btn-grey" style="height: 30px;width: 60px;">返回</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>

    </div>

</div>




<script src="__PUBLIC__/js/layui.all.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/jquery.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#signDate'
        });
        laydate.render({
            elem: '#endDate'
        });
		
		form.on('select(student)', function(data){
			var student_id = data.value;
			$.post("{:U('Contract/student_show')}",{student_id:student_id},function(data){
				var str = '<div class="form-item">'+
						'<div class="label-div">'+
						' <label class="form-label"><b>联系人</b></label>'+
					' </div>'+
					' <div class="input-block">'+
						'  <input type="text" name="contractLinkman" value="'+data.name+'" autocomplete="off" placeholder="请输入..." class="layui-input">'+
					'  </div>'+
				' </div>'+
				' <div class="form-item">'+
					' <div class="label-div">'+
						'   <label class="form-label"><b>联系电话</b></label>'+
					' </div>'+
					' <div class="input-block">'+
						' <input type="text" name="contractPhone" value="'+data.phone+'" autocomplete="off" placeholder="请输入十一位数手机号码..." class="layui-input">'+
						'</div>'+
					'</div>'+
					'<div class="form-item">'+
						'<div class="label-div">'+
							'<label class="form-label"><b>业务员</b></label>'+
						'</div>'+
						'<div class="input-block">'+
							'<input type="hidden" name="salesman" value="'+data.xsid+'"><p>'+data.xs_name+'</p>'+
						'</div>'+
					'</div>'+
					'<div class="form-item">'+
						'<div class="label-div">'+
							'<label class="form-label"><b>报名课程</b></label>'+
						'</div>'+
						'<div class="input-block">'+
							'<p>'+data.curriculum_name+'</p><br/><p>'+data.discount_name+'</p>'+
						'</div>'+
					'</div>'+
					'<div class="form-item">'+
						'<div class="label-div">'+
							'<label class="form-label"><b>合同费用</b></label>'+
						'</div>'+
						'<div class="input-block">'+
							'<input type="hidden" name="contractCost" value="'+data.cost+'"><span>'+data.cost+'</span>'+
						'</div>'+
					'</div>'+
				' <div class="form-item">'+
						'<div class="label-div">'+
						' <label class="form-label"><b>重要条款</b></label>'+
						'</div>'+
						'<div class="input-block input-block">'+
								'<textarea name="terms" placeholder="请输入内容" class="layui-textarea" style="height: 120px;"></textarea>'+
						'</div>'+
					'</div>';
				$("#student_show").html(str);
			},'json');

		})
    });
function check_form() {
	var contractName = $('input[name="contractName"]').val();
	if($.trim(contractName) == '') {
		alert('请输入合同名称');
		return false;
	}
	var contractId = $('input[name="contractId"]').val();
	if($.trim(contractId) == '') {
		alert('请输入合同编号');
		return false;
	}
	var student = $('select[name="student"]').val();
	if($.trim(student) == '') {
		alert('请选择报名学生');
		return false;
	}
	var contract_img = $('input[name="contract_img"]').val();
	if($.trim(contract_img) == '') {
		alert('请上传报名合同');
		return false;
	}
}
</script>
</body>
</html>
